package com.qianfeng.openapi.controller;

import com.github.pagehelper.PageInfo;
import com.qianfeng.openapi.bean.AjaxMessage;
import com.qianfeng.openapi.bean.TableData;
import com.qianfeng.openapi.pojo.Token;
import com.qianfeng.openapi.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys/token")
public class TokenController {
    @Autowired
    private TokenService tokenService;

    @RequestMapping("/del")
    public AjaxMessage deleteTokenByIds(int [] ids){
        tokenService.deleteTokenByIds(ids);
        return new AjaxMessage(true, "删除成功");
    }

    @RequestMapping("/update")
    public AjaxMessage updateToken(Token token){
        tokenService.updateToken(token);
        return new AjaxMessage(true, "修改成功");
    }

    @RequestMapping("/table")
    public TableData<Token> selectAll(int page, int limit, String name){
        Token token=new Token();
        token.setAccessToken(name);
        PageInfo<Token> pageInfo = tokenService.selectAll(page, limit, token);
        TableData<Token> tableData=new TableData<>();
        tableData.setCode(0);
        tableData.setMsg("成功");
        tableData.setCount(pageInfo.getTotal());
        tableData.setData(pageInfo.getList());
        return tableData;
    }
}
